package com.copm.ifm.servers.sys.controller;

import com.copm.ifm.base.api.pojo.PageDTO;
import com.copm.ifm.base.api.pojo.PageVO;
import com.copm.ifm.base.basic.ServiceResponse;
import com.copm.ifm.base.service.base.BaseController;
import com.copm.ifm.servers.sys.entity.SysMessageSend;
import com.copm.ifm.servers.sys.service.SysMessageSendService;
import com.copm.ifm.servers.sys.vo.SysMessageSendVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * 消息发送表相关接口类
 *
 * @author tp
 * @date 2021/1/4 11:39
 */
@Slf4j
@Api(tags = "消息发送/sys-message")
@RestController
@RequestMapping("/sys-message")
public class SysMessageSendController extends BaseController {

    @Autowired
    SysMessageSendService sysMessageSendService;

    @ApiOperation("分页-消息发送表")
    @PostMapping("/page")
    public ServiceResponse<PageVO<SysMessageSendVO>> page(@RequestBody PageDTO<SysMessageSend> param) {
        PageVO<SysMessageSendVO> result = sysMessageSendService.selectForPage(param);
        return success(result);
    }

    @ApiOperation("查询-根据by id")
    @GetMapping("/by/id")
    public ServiceResponse<SysMessageSendVO> getById(@ApiParam(value = "主键id", required = true)
                                                     @RequestParam int id) {
        return success(sysMessageSendService.selectVoById(id));
    }

    @ApiOperation("保存-消息发送表")
    @PostMapping
    public ServiceResponse<SysMessageSend> save(@RequestBody SysMessageSend entity) {
        sysMessageSendService.save(entity);
        return success(entity);
    }

    @ApiOperation("修改-消息发送表update")
    @PutMapping
    public ServiceResponse<SysMessageSend> update(@RequestBody SysMessageSend entity) {
        sysMessageSendService.updateEntityById(entity);
        return success(entity);
    }

    @ApiOperation("删除-根据by id")
    @DeleteMapping("/by/id")
    public ServiceResponse<?> deleteById(@ApiParam(value = "主键id", required = true)
                                         @RequestParam int id) {
        sysMessageSendService.updateDeleted(id);
        return success();
    }
}
